<template>
  <div>
    <!-- 面包屑导航区域 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/welcome' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>权限管理</el-breadcrumb-item>
      <el-breadcrumb-item>权限列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片区域 -->
    <el-card class="box-card">
      <!-- 权限列表数据 表格 -->
      <el-table :data="rightsList" stripe style="width: 100%" border>
        <el-table-column type="index" label="#"> </el-table-column>
        <el-table-column prop="authName" label="权限名称"> </el-table-column>
        <el-table-column prop="path" label="路径"> </el-table-column>
        <el-table-column label="权限等级">
          <template slot-scope="scope">
            <div>
              <el-tag v-if="scope.row.level == 0" size="small">一级</el-tag>
              <el-tag
                v-else-if="scope.row.level == 1"
                type="success"
                size="small"
                >二级</el-tag
              >
              <el-tag
                v-else-if="scope.row.level == 2"
                type="warning"
                size="small"
                >三级</el-tag
              >
            </div>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>
<script>
export default {
  data() {
    return {
      //type 决定获取的列表是list表单型 还是 tree树状
      type: "list",
      //存放权限列表的数组
      rightsList: [],
    };
  },
  methods: {
    //更新权限列表的函数
    async getRightsList() {
      //发送请求获取权限列表数据
      const { data: res } = await this.$http.get(`rights/${this.type}`);
      console.log(res);
      if (res.meta.status == 200) {
        //获取权限列表成功
        this.rightsList = res.data;
      } else {
        console.log("获取权限列表失败");
      }
    },
  },
  //vue一被创建就获取表单数据
  created() {
    this.getRightsList();
  },
};
</script>

<style lang="less" scoped>
</style>